//
//  HeaderView.swift
//  AirlineReservation
//
//  Created by Kevin on 2019/12/28.
//  Copyright © 2019 Kevin. All rights reserved.
//

import UIKit

class TableHeaderView: UIView {
    
    // View相关
    private lazy var userName = UILabel(title: "王洪振")
    private lazy var detailText = UILabel(title: "查看个人详细资料")
    private lazy var rightArrow = UIImageView(image: UIImage(named: "arrow_12x12"))
    private lazy var header = UIImageView(image: UIImage(named: "login_default_icon"))
    // 计算相关
    private lazy var y = bounds.size.height * 0.25
    private lazy var headerSize = bounds.size.height * 0.5
    // 回调相关
    var enterCallBack:clickCallback?
    
    override func layoutSubviews() {
        // 头像
        header.contentMode = .scaleAspectFit
        header.frame = CGRect(x: MARGIN, y: y, width: headerSize, height: headerSize)
        addSubview(header)
        // 用户名
        userName.textColor = COLOR_NICE
        userName.font = UIFont.systemFont(ofSize: 16)
        userName.frame = CGRect(x: MARGIN * 1.5 + headerSize, y: y, width: SCREEN_WIDTH * 0.7, height: MARGIN * 2)
        addSubview(userName)
        // 查看个人资料
        detailText.textColor = UIColor.lightGray
        detailText.font = UIFont.systemFont(ofSize: 14)
        detailText.frame = CGRect(x: MARGIN * 1.5 + headerSize, y: y + headerSize * 0.5, width: SCREEN_WIDTH * 0.7, height: MARGIN * 2)
        addSubview(detailText)
        // 右箭头
        rightArrow.contentMode = .scaleAspectFit
        rightArrow.frame = CGRect(x: SCREEN_WIDTH - MARGIN * 2 - 5, y: y + headerSize * 0.5, width: MARGIN, height: MARGIN)
        addSubview(rightArrow)
        // 下滑线
        let line = UIView(frame: CGRect(x: 0, y: frame.height - MARGIN25, width: SCREEN_WIDTH, height: MARGIN25))
        line.backgroundColor = COLOR_LINE
        addSubview(line)
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        if let complete = enterCallBack {
            complete()
        }
    }
}
